
#include "unistd.h"

#include <xdc/std.h>

#include <ti/sdo/ce/CERuntime.h>
#include <ti/sdo/dmai/Dmai.h>

#include <media/davinci/imp_previewer.h>

#include "dmai_env.h"

extern int Resizer_continuous_config(void);
extern int Previewer_continuous_config(void);
extern int Resizer_continuous_delete(int fd);
extern int Previewer_continuous_delete(int fd);

static int resizer_fd = -1, previewer_fd = -1;

int
dmai_env_init (void)
{
	/* Initialize Codec Engine runtime */
	CERuntime_init();

	/* Initialize Davinci Multimedia Application Interface */
	Dmai_init();

	resizer_fd = Resizer_continuous_config();
	previewer_fd = Previewer_continuous_config();

	return Dmai_EOK;
}

void
dmai_env_destroy (void)
{
	if (previewer_fd > 0) {
		Previewer_continuous_delete(previewer_fd);
		previewer_fd = -1;
	}

	if (resizer_fd > 0) {
		Resizer_continuous_delete (resizer_fd);
		resizer_fd = -1;
	}
}
